package com.bidevalution.controller.api;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.bidevalution.business.dto.BeMethodHeaderDTO;
import com.bidevalution.business.service.BeMethodHeaderService;
import com.bidevalution.dao.entity.BeLayoutConfig;
import com.bidevalution.dao.entity.BeMethodColumn;
import com.bidevalution.dao.entity.BeMethodHeader;
import com.bidevalution.service.layout.FormControl.ControlType;
import com.google.gson.Gson;
import com.qtp.core.model.Response;
import com.qtp.core.util.GsonUtil;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

@Slf4j
@RestController
@RequestMapping("/beMethodHeader")
@Api(tags = "环节配置布局头部区域管理")
public class BeMethodHeaderController extends BaseController {
	@Autowired
	private BeMethodHeaderService beMethodHeaderService;

	@PostMapping("/saveMethodHeader")
	@ApiOperation(value = "保存头部区域数据", notes = "保存头部区域数据")
	public Response<String> save(
			@ApiParam(name = "methodStepId", value = "环节ID", required = true) @RequestParam("methodStepId") String methodStepId,
			@ApiParam(name = "methodHeaderList", value = "按钮数组json字符串", required = true) @RequestParam("methodHeaderList") String methodHeaderList) {
		try {
			beMethodHeaderService.save(methodStepId,new Gson().fromJson(methodHeaderList,BeMethodHeaderDTO[].class));
			return Response.ok();
		} catch (Exception e) {
			log.error(e.getMessage(), e);
			return Response.fail("保存失败");
		}
		
	}
	@GetMapping("/getControlTypeList")
	@ApiOperation(value = "查询控件类型列表", notes = "返回控件类型列表", response = BeLayoutConfig.class)
	public Response<Map<String, String>> selectList() {
		Map<String, String> dataMap = new HashMap<String, String>();
		for(ControlType controlType:ControlType.values()) {
			dataMap.put(controlType.name(), controlType.name());
		}
		return Response.ok(dataMap);
	}
	@ApiOperation(value = "按钮区域查询", notes = "按钮区域查询", response = BeMethodHeader.class)
	@ApiImplicitParams({
			@ApiImplicitParam(name = "methodStepId", value = "环节ID", required = true, dataType = "String", paramType = "query")})
	@GetMapping("/getMethodHeaderList")
	public Response<List<BeMethodHeader>> selectList(@RequestParam("methodStepId") String methodStepId) {
		return Response.ok(beMethodHeaderService.selectForList(methodStepId));
	}
	@ApiOperation(value = "删除控件", notes = "根据seqid删除数据", response = BeMethodHeader.class)
	@ApiImplicitParams({
			@ApiImplicitParam(name = "seqId", value = "主键ID", required = true, dataType = "String", paramType = "query")})
	@PostMapping("/deleteById")
	public Response<List<BeMethodHeader>> deleteById(@RequestParam("seqId") String seqId) {
		beMethodHeaderService.deleteById(seqId);
		return Response.ok();
	}
}
